let cacheData = [];

export class Cache {
    constructor (data, timeout) {
        this.data = data
        cacheData.push(this.data);
        setTimeout(() => {
            this.clear()
        }, timeout)
    }
}

Cache.prototype.isRepeat = function isRepeat() {
    return this.isAlreadyExist()
}

Cache.prototype.clear = function clear() {
    for (let i = cacheData.length; i > 0; i--) {
        if (cacheData[i] === this.data) cacheData.splice(i, 1);
    }
}

Cache.prototype.isAlreadyExist = function isAlreadyExist() {
    return cacheData.filter((data) => data === this.data).length >= 2
}
